﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.XCMG.Util;

namespace PMS.XCMG.Entity
{
    /// <summary>
    /// 生产区域
    /// </summary>
    public partial class WorkshoArea : BusEntity
    {
        /// <summary>
        /// 生产车间ID
        /// </summary>
        public string WorkshoId { set; get; }
        /// <summary>
        /// 工艺流程步骤ID
        /// </summary>
        public string CraftStepId { set; get; }
        /// <summary>
        /// 区域编码
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 区域名称
        /// </summary>
        public string Name { get; set; }
    }

    public partial class WorkshoArea : BusEntity
    {
        /// <summary>
        /// 生产车间实体
        /// </summary>
        public Worksho Sho { set; get; }
        /// <summary>
        /// 工艺流程步骤实体
        /// </summary>
        public CraftStep Step { set; get; }
        /// <summary>
        /// 生产单元实体列表
        /// </summary>
        public List<WorkshoUnit> Units { set; get; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class WorkshoAreaTypeConfig : BusEntityTypeConfig<WorkshoArea>, IEntityTypeConfiguration<WorkshoArea>
    {
        public override void Configure(EntityTypeBuilder<WorkshoArea> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            builder.HasOne(p => p.Sho).WithMany(p => p.Areas).HasForeignKey(p => p.WorkshoId);
            builder.HasOne(p => p.Step).WithMany().HasForeignKey(p => p.CraftStepId);
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.WorkshoId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Code).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Name).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            #endregion

            #region 备注
            builder.HasComment("生产区域");
            builder.Property(p => p.WorkshoId).HasComment("生产车间ID");
            builder.Property(p => p.Code).HasComment("区域编码");
            builder.Property(p => p.Name).HasComment("区域名称");
            #endregion

            #region 种子数据
            builder.HasData(new WorkshoArea() { Id = "C91001", WorkshoId = "C9", CraftStepId = "1001", Name = "来料缓存区", Code = "C91001", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoArea() { Id = "C91002", WorkshoId = "C9", CraftStepId = "1002", Name = "拼板卷圆区", Code = "C91002", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoArea() { Id = "C91003", WorkshoId = "C9", CraftStepId = "1003", Name = "成型件预装区", Code = "C91003", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoArea() { Id = "C91004", WorkshoId = "C9", CraftStepId = "1004", Name = "筒体加工区", Code = "C91004", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoArea() { Id = "C91005", WorkshoId = "C9", CraftStepId = "1005", Name = "筒体检测区", Code = "C91005", CreateUserId = "1", ModifyUserId = "1" });
            #endregion
        }
    }
}
